package com.csx.springcloud.invoke.resttemplate.ext;

import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;

import java.io.IOException;
import java.net.URI;

/**
 * RestTemplate 自定义异常处理
 */
public class RestCustomErrorHandler extends DefaultResponseErrorHandler {

    @Override
    public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {

        System.out.println(url);
        System.out.println(method);
        String statusText = response.getStatusText();
        HttpStatusCode statusCode = response.getStatusCode();
        int rawStatusCode = response.getRawStatusCode();

        System.out.println(statusText);
        System.out.println(statusCode);
        System.out.println(rawStatusCode);
    }
}
